<template>
    <div class="layerRtb layerRtb-threecolumn">
        <three-title :title="{name:'验证激活'}"></three-title>
        <div class="layerRtb-scroll thinScroll" v-scrollHeight="437">
            <!-- <div class="analyItem">
                <p class="analyItemTit tx-center" :class="(this.stageInfo.mobile=== undefined || this.stageInfo.mobile=== '' || this.stageInfo.mobile=== null) ? '' : 'analyLightGreen'">信息</p>
                <div class="analyItemCon">
                    <p class="col-md-3">
                        <span class="cLightGray pr8">姓名</span>
                        <span>{{this.stageInfo.user_name ? this.stageInfo.user_name : ''}}</span>
                    </p>
                    <p class="col-md-3">
                        <span class="cLightGray pr8">手机号</span>
                        <span>{{this.stageInfo.mobile ? this.stageInfo.mobile : ''}}</span>
                    </p>
                    <p class="col-md-3">
                        <span class="cLightGray pr8">密码</span>
                        <span>123456</span>
                    </p>
                    <input type="button" value="生成卡号" class="uiBtn-normal uiBtn-blue SubmitBtn col-md-3" @click="kahao()">
                </div>
            </div> -->
            <div class="analyItem">
                <p class="analyItemTit tx-center">短信</p>
                <div class="analyItemCon">
                        {{this.userInfo.u_name}}{{this.userInfo.sex === '女' ? '女士' : '先生'}}您好，欢迎登录瑞祥企业端：https://pi.rxjy.com/Home/AppDownload，您的账号：{{this.userInfo.phone}}，期待与您合作愉快。客服热线：010-56134592
                </div>
            </div>
            <div class="analyItem">
                <p class="analyItemTit tx-center" :class="(this.messageTime=== undefined || this.messageTime=== '' || this.messageTime=== null) ? '' : 'analyLightGreen'">状态</p>
                <div class="analyItemCon">
                    <p v-if="this.messageTime === null || this.messageTime === '' || this.messageTime === undefined">
                        <span class="cLightGray pr8 col-md-6 cRed">未发送</span>
                        <input type="button" value="发送短信" class="uiBtn-normal uiBtn-blue SubmitBtn" @click="MappingButton()">
                    </p>
                    <p v-else>
                        <span class="cLightGray pr8 col-md-6">发送时间</span>
                        <span>{{this.messageTime}}</span>
                    </p>
                </div>
            </div>
            <div class="analyItem">
                <p class="analyItemTit tx-center" :class="(stageInfo.activation_app === undefined || stageInfo.activation_app === '' || stageInfo.activation_app === null || Number(stageInfo.activation_app) === 1) ? '' : 'analyLightGreen'">APP</p>
                <div class="analyItemCon">
                    <p v-if="stageInfo.activation_app === undefined || stageInfo.activation_app === '' || stageInfo.activation_app === null || stageInfo.activation_app === 1">
                        <span class="cLightGray pr8 col-md-6 cRed">未激活</span>
                    </p>
                    <p v-else>
                        <span class="cLightGray pr8 col-md-6">激活时间</span>
                        <span>{{this.messageTime}}</span>
                    </p>
                </div>
            </div>
            <div class="analyItem">
                <p class="analyItemTit tx-center">个人端</p>
                <div class="analyItemCon">
                    <p class="col-md-4"> <span class="cLightGray pr8">最近登录时间</span><span>{{this.lastTime}}</span> </p>
                    <!-- <input type="button" value="发送短信" class="uiBtn-normal uiBtn-blue SubmitBtn" @click="MappingButton()"> -->
                </div>
                <!-- <div class="analyItemCon" v-if="this.lastTime !== null && this.lastTime !== ''">
                    <p class="col-md-4"><span class="cLightGray pr8 cRed">短信已发</span></p>
                </div> -->
            </div>
        </div>

        <div class="layerRtb-footer">
              <div class="analyItem">
                <p class="analyItemTit tx-center">综合</p>
                <div class="analyItemCon">
                    <p class="fl">
                        <span v-if="(this.stageInfo.activation_app === null || this.stageInfo.activation_app === '' || this.stageInfo.activation_app === undefined || this.stageInfo.activation_app === 1) ||
                            (this.sendMessageTime === undefined || this.sendMessageTime === '' || this.sendMessageTime === null)
                            " class="circlemark circlemark-lightRed">待</span>
                        <span v-else class="circlemark circlemark-lightGreen">全</span>
                    </p>
                </div>
            </div>
        </div>
          <transition-group class="animated faster" enter-active-class="animated faster slideInRight" leave-active-class="animated faster slideOutRight">
         </transition-group>
    </div>
</template>
<script>
import { mapGetters } from 'vuex'
import { sendMessageTime, SendInvitation, updateStageInfoByleId, GetAppLastLoginTime, getAppCardNoByUid } from '../../Resources/Api/index'
export default {
    components: {
    },
    data () {
        return {
            userInfo: {},
            stageInfo: {},
            messageTime: '', // 发送短信的时间
            lastTime: '' // 最近登录时间
        }
    },
    created () {
        this.stageInfo = this.$route.query.stageInfo
        this.userInfo = this.$route.query.userInfoFn
        this.messageTime = this.$route.query.sendMessageTime
        this.getAppCardNoByUid()
    },
    methods: {
        getAppCardNoByUid () {
            getAppCardNoByUid({
                uid: this.leftInfo.uid // 5081
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    // this.appCardNo = result.data.Body
                    this.GetAppLastLoginTime(result.data.Body)
                }
            }).catch(err => {
                console.log('查询指定的用户的卡号失败，异常信息：' + err)
            })
        },
        // 查询最近登录时间
        GetAppLastLoginTime (value) {
            // alert(value)
            GetAppLastLoginTime({
                CardNo: value,
                AppId: this.leftInfo.rs_app_id // '9bbfb73d-bd2f-40a1-9529-310c126aaee2' // this.leftInfo.rs_app_id
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    this.lastTime = result.data.Body.replace('/', '-')
                    this.lastTime = this.lastTime.replace('/', '-')
                }
            }).catch(err => {
                console.log('查询最近登录时间失败，异常信息：' + err)
            })
        },
        MappingButton () {
            SendInvitation({
                app_id: this.leftInfo.rs_app_id
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    this.sendMessageTimeFn()
                }
            })
        },
        sendMessageTimeFn () {
            sendMessageTime({
                uid: this.leftInfo.uid
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    this.updateStageInfoByleIdFn()
                    // this.$router.push(this.$route.matched[1].path)
                }
            }).catch(err => {
                console.log('保存发送短信时间失败，异常信息：' + err)
            })
        },
        updateStageInfoByleIdFn () {
            updateStageInfoByleId({
                uid: this.leftInfo.uid,
                activationApp: 0 // 激活状态：0-是，1-否
            }).then(result => {
                if (Number(result.data.StatusCode) === 0) {
                    layer.msg('发送成功')
                    this.$router.push(this.$route.matched[1].path)
                }
            }).catch(err => {
                console.log('用户激活失败，异常信息：' + err)
            })
        }
    },
    computed: {
        ...mapGetters(['leftInfo'])
    },
    watch: {
    }
}

</script>
